//
//  AUHomeModule.swift
//  AwesomeUHomeModule_Example
//
//  Created by Miss_Special on 2018/4/11.
//  Copyright © 2018 CocoaPods. All rights reserved.
//

import UIKit
import AwesomeUMainModule
import AwesomeUSharedModule

// MARK: - 通用配置
/// 通用_文字颜色_蓝色
let common_textColor_black: UIColor = UIColor(au_rgbColor: 50, g: 50, b: 50)
/// 通用_文字颜色_蓝色
let common_textColor_blue: UIColor = UIColor(au_rgbColor: 79, g: 113, b: 148)
/// 通用_文字颜色_灰色
let common_textColor_gray: UIColor = UIColor(au_rgbColor: 163, g: 163, b: 163)

/// 通用_背景色
let common_backgroundColor_gray: UIColor = UIColor(au_rgbColor: 242, g: 242, b: 242)

/// 大图截取的高度
let au_bigImageRemainingHeight: CGFloat = 250

// MARK: - HomeModule
public class AUHomeModule {
    
    public static let sharedHomeModule = AUHomeModule()
    
    private init() { }
    
    public var testActionCallback: (() -> ())?
    
    // MARK: - functions
    public func homeVC() -> UIViewController {
        let nav = AUNavController(rootViewController: AUEssenceVC())
        return nav
    }
    
    static func imageFromBundle(bundle: Bundle, imageName: String, type: String = "png") -> UIImage? {
        if let bundleDict = bundle.infoDictionary {
            let bundleName = bundleDict["CFBundleName"] ?? ""
            if let imagePath = bundle.path(forResource: imageName, ofType: type, inDirectory: "\(bundleName).bundle") {
                if let image = UIImage(contentsOfFile: imagePath) {
                    return image
                }
            }
        }
        return nil
    }
}

// MARK: - 中间件扩展
public extension AUSharedModule {
    
    public func homeModule_test() {
        let urlString = "home://AUHomeModule_Wrapper/home_test_wrapper:?something=xxxxxxx"
        let bundle = Bundle.init(for: type(of: AUHomeModule.sharedHomeModule) as AnyClass)
        if let url = URL(string: urlString) {
            au_performActionWithUrl(url: url, bundle: bundle, completion: nil)
        }
    }
}
